//package com.lh.config;
//
//import org.activiti.api.process.runtime.ProcessRuntime;
//import org.activiti.api.runtime.shared.query.Page;
//import org.activiti.api.runtime.shared.query.Pageable;
//import org.activiti.api.task.runtime.TaskRuntime;
//import org.activiti.engine.RepositoryService;
//import org.activiti.engine.RuntimeService;
//import org.activiti.engine.TaskService;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.security.core.Authentication;
//import org.springframework.security.core.context.SecurityContextHolder;
//
//@Configuration
//public class ActivitiConfig {
//
//    // 注入Activiti服务
//    @Autowired
//    private RepositoryService repositoryService;
//
//    @Autowired
//    private RuntimeService runtimeService;
//
//    @Autowired
//    private TaskService taskService;
//
//    @Autowired
//    private ProcessRuntime processRuntime;
//
//    @Autowired
//    private TaskRuntime taskRuntime;
//
//    /**
//     * 配置当前用户提供者
//     */
//    @Bean
//    public org.activiti.api.spring.security.SecurityContextUserDetailsService securityContextUserDetailsService() {
//        return () -> {
//            Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
//            if (authentication == null) {
//                return null;
//            }
//            return new org.activiti.api.spring.security.model.SecurityUser(authentication);
//        };
//    }
//
//    /**
//     * 初始化流程引擎，打印基本信息
//     */
//    @Bean
//    public String initProcessEngine() {
//        System.out.println("流程引擎初始化完成！");
//        System.out.println("流程定义数量: " + repositoryService.createProcessDefinitionQuery().count());
//        System.out.println("正在运行的流程实例数量: " + runtimeService.createProcessInstanceQuery().count());
//
//        // 打印所有流程定义
//        Page<org.activiti.api.process.model.ProcessDefinition> processDefinitions =
//                processRuntime.processDefinitions(Pageable.of(0, 10));
//        System.out.println("可用的流程定义数量: " + processDefinitions.getTotalItems());
//
//        return "流程引擎初始化成功";
//    }
//}